﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MethodWorx.CMS.Plugins;
using System.Web;
using System.Web.UI;

namespace MethodWorx.CMS.Workflow
{
    public abstract class WorkflowComponent<TController> : IWorkflowComponent
    {
        private Plugin plugin;
        private IdeExtension extension;

        public WorkflowComponent(Plugin plugin)
        {
            this.plugin = plugin;

            this.extension = new IdeExtension()
                                 {
                                     Controller = typeof (TController),
                                     DisplayName = this.Name,
                                     Name = this.Name,
                                     Id = this.Id,
                                     WebEditor =
                                         new AssemblyResourceReference(this.GetType().Assembly,
                                                                       this.GetType().Namespace + "." + this.View),
                                    Plugin = this.plugin
                                };


            //  register the ide extension with the plugin
            this.plugin.RegisterIdeExtension(extension);
        }


        public abstract Guid Id { get; }
        public abstract string Category { get; }
        public abstract string Name { get;  }
        public abstract string Description { get;  }
        public virtual string View { get { return "ConfigurationView.ascx"; } }

        public Plugins.IdeExtension ConfigurationIdeExtension
        {
            get { return this.extension;  }
        }

        public virtual StepExecutionResult Execute(IWorkflowExecutionContext context, IWorkflowConfiguration configuration)
        {
            return StepExecutionResult.Ok();
        }
    }
}
